package com.easyoffer.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;


@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {
    private int database;
    private String host;
    private int port;
    private int timeout;
    private String password;

    @PostConstruct
    public void init(){
        System.out.println("host:"+host+"port:"+port+"timeout:"+timeout+"password:"+password);
    }

    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.useSingleServer()
                .setDatabase(database)
                .setAddress("redis://"+host+":"+port)
                .setTimeout(timeout)
                .setPassword(password);
        return Redisson.create(config);
    }
}
